<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>正则扩展-命名捕获分组</title>
</head>

<body>

  <script>
    /* // 声明一个字符串
    let str = '<a href="http://www.atguigu.com">尚硅谷</a>'

    // 提取URL与标签文本
    const reg = /<a href="(.*)">(.*)<\/a>/

    const result = reg.exec(str)
    console.log(result[1]); // http://www.atguigu.com
    console.log(result[2]); // 尚硅谷 */

    // 声明一个字符串
    let str = '<a href="http://www.atguigu.com">尚硅谷</a>'

    // 提取URL与标签文本
    const reg = /<a href="(?<url>.*)">(?<text>.*)<\/a>/

    const result = reg.exec(str)
    console.log(result.groups.url); // http://www.atguigu.com
    console.log(result.groups.text); // 尚硅谷
  </script>
</body>

</html>